<!-- 信息系统列表页面 -->
<template>
  <div
    class="system-information-list"
    v-loading="globalLoading"
  >
    <div class="noticeShowM">
      <p>
        导入excel文件时，请确保导入数据与模板的数据一致。<span class="download_a" @click="downloadFile">点击下载模板</span>
      </p>
    </div>
    <TipTotal :title="(system.name?system.name+'-':'')+'列表'">
      <div>
        <OperateSystemInformationList
          :system="system"
          :resetData="resetData"
          :resetGlobalLoading="resetGlobalLoading"
        />
      </div>
      <template slot="total">
        <p class="totalR" v-if="total">信息总数：{{total}}</p>
      </template>
    </TipTotal>

    <!-- 查询列表 -->
    <SearchSystemInformationList
      :search="search"
      :resetData="resetData"
      :reset="reset"
    />

    <!-- 列表数据展示 -->
    <DataTable
      ref="systemInformationList"
      :search="search"
      :dataTotal="dataTotal"
      :system="system"
    />
  </div>
</template>

<script>
import TipColla from '@/components/common/TipColla.vue'
import TipTotal from '@/components/common/TipTotal.vue'
import OperateSystemInformationList from '@/components/main/user/system/information/OperateSystemInformationList.vue'
import SearchSystemInformationList from '@/components/main/user/system/information/SearchSystemInformationList.vue'
import DataTable from '@/components/main/user/system/information/DataTable.vue'
export default {
  created () {
    let query = this.$route.query
    if (!query || !query.sid) {
      this.$message.error('未能获取到正确的数据')
      return
    }
    this.systemId = query.sid
    // 获取系统信息
    this.$post('/system/info', { id: this.systemId }).then((resoponse) => {
      this.system = resoponse
      this.globalLoading = false
      this.$store.dispatch('navPrependNameByPath', { prependName: this.system.name + '-', path: this.$route.fullPath })
    })
  },
  data () {
    return {
      // 全局加载中
      globalLoading: true,
      systemId: 0,
      total: 0,
      // 当前的系统
      system: {},
      // search 查询数据
      search: {
        keyword: '',
        status: -1
      }
    }
  },
  methods: {
    // 设置总数
    dataTotal (total) {
      this.total = '' + total
    },
    // 重置数据
    resetData (obj) {
      if (typeof obj === 'object') {
        this.$refs['systemInformationList'].resetData(obj)
      } else {
        this.$refs['systemInformationList'].resetData()
      }
    },
    reset (search) {
      this.search = {
        keyword: ''
      }
    },
    resetGlobalLoading (bool) {
      this.globalLoading = bool
    },
    downloadFile () {
      // 获取excel模板下载地址
      this.$post('/system/information/excel-demo', { systemId: this.systemId }).then((resoponse) => {
        if (resoponse) {
          let url = resoponse
          window.open(url, '_blank')
        }
      })
    }
  },
  components: {
    TipColla,
    TipTotal,
    OperateSystemInformationList,
    SearchSystemInformationList,
    DataTable
  }
}

</script>
<style scoped lang="scss">
.noticeShowM {
  border-left: 4px solid #409EFF;
  padding: 15px;
  font-size: 13px;
  line-height: 1.7;
  background: #F0F8FF;
  margin-bottom: 20px;
  .download_a{
    color: #409EFF;
    cursor: pointer;
    &:hover{
      text-decoration: underline;
    }
  }
}
.totalR {
  float:right;
  margin-right:8px;
  margin-top:6px;
  font-size: 14px;
  color:#666;
}
</style>
